'use client';

import React from 'react';
import { Form, Select, Switch } from 'antd';
import type { FormInstance } from 'antd/es/form';
import { UserInfo, UserRole, UserStatus } from '@/types/user';

interface UserSettingsFormProps {
  form: FormInstance;
  mode: 'edit' | 'view';
  initialValues: Partial<UserInfo>;
  onSubmit: (values: Record<string, unknown>) => Promise<void>;
}

const UserSettingsForm: React.FC<UserSettingsFormProps> = ({
  form,
  mode,
  initialValues,
  onSubmit,
}) => {
  const readonly = mode === 'view';

  return (
    <Form
      form={form}
      layout="vertical"
      initialValues={initialValues}
      onFinish={onSubmit}
    >
      <Form.Item
        label="用户角色"
        name="role"
        rules={[{ required: true, message: '请选择用户角色' }]}
      >
        <Select
          disabled={readonly}
          placeholder="请选择用户角色"
          options={[
            { label: '超级管理员', value: UserRole.SUPER_ADMIN },
            { label: '仪器管理员', value: UserRole.INSTRUMENT_MANAGER },
            { label: '仪器操作员', value: UserRole.INSTRUMENT_OPERATOR },
            { label: '财务', value: UserRole.FINANCE },
            { label: '1级用户', value: UserRole.LEVEL_1_USER },
            { label: '2级用户', value: UserRole.LEVEL_2_USER },
            { label: '3级用户', value: UserRole.LEVEL_3_USER },
          ]}
        />
      </Form.Item>

      <Form.Item
        label="用户状态"
        name="status"
        rules={[{ required: true, message: '请选择用户状态' }]}
      >
        <Select
          disabled={readonly}
          placeholder="请选择用户状态"
          options={[
            { label: '正常', value: UserStatus.NORMAL },
            { label: '禁用', value: UserStatus.DISABLED },
          ]}
        />
      </Form.Item>

      <Form.Item
        label="实名认证"
        name="isVerified"
        valuePropName="checked"
      >
        <Switch 
          disabled={readonly}
          checkedChildren="已认证"
          unCheckedChildren="未认证"
        />
      </Form.Item>
    </Form>
  );
};

export default UserSettingsForm;
